const app = getApp();
import grace from "../../../utils/grace.js";

grace.page({
    /**
     * 页面的初始数据
     */
    data: {
        school_name: '',
        class_id: 0,
        class_name: '',
        students: [],
        total: {}
    },
    onShow() {
        let that = this;
        that.$data = {
            'school_name': wx.getStorageSync('school_name'),
            'class_id': wx.getStorageSync('class_id'),
            'class_name': wx.getStorageSync('class_name')
        }

        that.getList();
    },
    getList() {
        let that = this;

        wx.showLoading({
            title: '加载中...',
        })
        let url = app.globalData.api + '/api/v1.0/teacher/students/' + wx.getStorageSync('partner_id');
        that.$http.get(url, {token: wx.getStorageSync('token')}).then((res) => {
            if (res.data.code == 0) {
                that.$data = {
                    'students': res.data.data.students,
                    'total': res.data.data.total
                }
            } else if (res.data.code == 10001) {
                wx.navigateTo({
                    url: "/pages/common/authorize/index"
                })
            } else {
                that.$data.insures = [];
            }
          wx.hideLoading();
        }).catch(err => {
            console.log(err.status, err.message);
        });
    },
    goto_insure(e){
        wx.navigateTo({
            url: '/pages/home/teacher/insure_submit?student_id=' + e.currentTarget.dataset.id + '&student_name=' + e.currentTarget.dataset.name + '&insure_state=' + e.currentTarget.dataset.state
        })
    }
})